﻿using System;
using System.Web;

namespace Warranty.Data.DataContextStorage
{
    public class HttpDataContextStorageContainer : IDataContextStorageContainer
    {
        private string dataContextKey = "DataContext";

        public WarrantyEntities GetDataContext()
        {
            WarrantyEntities objectContext = null;
            if (HttpContext.Current.Items.Contains(dataContextKey))
            {
                objectContext = (WarrantyEntities)HttpContext.Current.Items[dataContextKey];
            }

            return objectContext;
        }

        public void Store(WarrantyEntities warranty)
        {
            if (HttpContext.Current.Items.Contains(dataContextKey))
                HttpContext.Current.Items[dataContextKey] = warranty;
            else
                HttpContext.Current.Items.Add(dataContextKey, warranty);
        }
    }
}